#pragma once
#include <fstream>
#include "../splitLib/Jieba.hpp"

class Util
{
    public:
    static bool ReadFile(const std::string& file,std::string* out)
    {
        std::ifstream ifs(file);
        if(!ifs.is_open()){
            return false;
        }
        std::ostringstream oss;
        oss << ifs.rdbuf(); // 读取整个文件内容到字符串流
        *out = oss.str();
        ifs.close();
        return true;
    }
    static bool WriteFile(const std::string& src,const std::string& file)
    {
        std::ofstream ofs(file,std::ios::out | std::ios::trunc | std::ios::binary);
        if(!ofs.is_open()){
            LOG(logLevel::ERROR)<<"Open file error";
            return false;
        }
        ofs<<src;
        if (ofs.fail()) {
            LOG(logLevel::ERROR)<<"Write into "<<file<<"error";
            return false;
        }
        ofs.close();
        return true;
    }
    static void Split(const std::string src,const std::string& sep,std::vector<std::string>* vec)
    {
        int start = 0;
        while(start < src.size())
        {
            //888,,,d
            int end = src.find(sep,start);
            if(end==std::string::npos)
            {
                vec->push_back(std::move(src.substr(start)));
                break;
            }
            if(end!=start){
                vec->push_back(std::move(src.substr(start,end-start))); 
            }
            start = end+1;
        }
    }



};

const char* const DICT_PATH = "./dict/jieba.dict.utf8";
const char* const HMM_PATH = "./dict/hmm_model.utf8";
const char* const USER_DICT_PATH = "./dict/user.dict.utf8";
const char* const IDF_PATH = "./dict/idf.utf8";
const char* const STOP_WORD_PATH = "./dict/stop_words.utf8";
class test{
    private:
        static int a;
};
int test::a = 1;

class JiebaUtil{
    private:
        static cppjieba::Jieba jieba;
    public:
        static void CutString(const std::string& src,std::vector<std::string>* out){
            jieba.CutForSearch(src,*out);
        }

};

cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);



